import React, { Component } from 'react'
import PubSub from 'pubsub-js'
import axios from 'axios'
export default class search extends Component {
  searchName = () => {
    const { inputElment: { value: searchKey } } = this
    PubSub.publish("message",{isLoading:true})
    axios.get(`http://localhost:3000/api/search?q=${searchKey}`)
      .then(
        res => {
          PubSub.publish("message",{users:res.data})
          PubSub.publish("message",{isLoading:false})
        },
        err => {
          console.log(err)
        }
      )
  }
  render() {
    return (
      <div className="search">
        <input ref={c => this.inputElment = c} type="text" />&nbsp;
        <button onClick={this.searchName}>search</button>
      </div>
    )
  }
}
